package 查找;

/**
 * @Author: biubiu0002
 * @Date: 2021-09-15 0:23
 **/
public class 寻找峰值 {
    public static void main(String[] args) {
        int[] nums = {1,2,3,1};
        System.out.println(findPeakElement(nums));

    }

    public static int findPeakElement(int[] nums) {
        return find(nums,0,nums.length-1);

    }

    public static int find(int[]nums,int left,int right){
        int a=0,b=0;
        if(left<right){
            int mid = left + ((right - left) >>> 1);
            if(mid==0||mid==nums.length-1){
                return 0;
            }


            System.out.println("left="+ left+"mid="+mid+"right="+right);
            if (nums[mid - 1] < nums[mid] && nums[mid] > nums[mid + 1]) {
                System.out.println("这个是答案"+mid);
                return mid;
            }

            a=find(nums, left, mid-1);
            b=find(nums, mid, right);


        }
        return Math.max(a,b);
    }
}
